package cn.stylefeng.guns.modular.goods.company.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.goods.company.entity.Company;
import cn.stylefeng.guns.modular.goods.company.model.params.CompanyParam;
import cn.stylefeng.guns.modular.goods.company.model.result.CompanyResult;
import cn.stylefeng.guns.modular.goods.company.service.CompanyService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.kernel.model.response.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


/**
 * 控制器
 *
 * @author syt
 * @Date 2020-10-12 13:29:43
 */
@Controller
@RequestMapping("/company")
public class CompanyController extends BaseController {

    private String PREFIX = "/company";

    @Autowired
    private CompanyService companyService;

    /**
     * 跳转到主页面
     *
     * @author syt
     * @Date 2020-10-12
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/company.html";
    }

    /**
     * 新增页面
     *
     * @author syt
     * @Date 2020-10-12
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/company_add.html";
    }

    /**
     * 编辑页面
     *
     * @author syt
     * @Date 2020-10-12
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/company_edit.html";
    }

    /**
     * 新增接口
     *
     * @author syt
     * @Date 2020-10-12
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(CompanyParam companyParam) {
        this.companyService.add(companyParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *
     * @author syt
     * @Date 2020-10-12
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(CompanyParam companyParam) {
        this.companyService.update(companyParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author syt
     * @Date 2020-10-12
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(CompanyParam companyParam) {
        this.companyService.delete(companyParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author syt
     * @Date 2020-10-12
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(CompanyParam companyParam) {
        Company detail = this.companyService.getById(companyParam.getCompanyId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author syt
     * @Date 2020-10-12
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(CompanyParam companyParam) {
        return this.companyService.findPageBySpec(companyParam);
    }

    @ResponseBody
    @RequestMapping("/getAll")
    public List<CompanyResult> getlist(CompanyParam companyParam) {
        return this.companyService.getALL(companyParam);
    }

}


